Skip to content

Fix invalid schools in our database#867

Merged
zetter-rpf merged 1 commit into
mainfrom
fix-invalid-schools
Jun 12, 2026
Merged

Fix invalid schools in our database#867
zetter-rpf merged 1 commit into
mainfrom
fix-invalid-schools

Conversation

@zetter-rpf

@zetter-rpf zetter-rpf commented Jun 12, 2026

Copy link
Copy Markdown
Contributor

Status

What's changed?

We've added validation that invalidates existing schools we already have in our database. This means that that updates to those schools may fail and cause errors.

Generally, when we add validation we should make sure it doesn't invalidate existing records.

Here I've done two things:

  • Add on: :create to the new validations where schools have some invalid records
  • Add unless: :rejected to items with a unique condition where new signups may overlap with rejected schools.

Using on: :create is safe to do as we don't allow users to update these values. If we wanted to do this in the future we could provide a more complex condition (e.g. if a new record or that field has changed)

I've documented the errors in this sheet. Some of the optional invalid codes could be fixed manually by nulling them if they aren't required, but since that can't be done for the required codes, I've handled them all the same way.

After deploy

Confirm all schools are valid by running School.all.reject{|x| x.valid?}.count

We've added validation that makes existing schools we already have in our database. This means that that updates to those schools may fail and cause errors.

Generally, when we add validation we should make sure it doesn't invalidate existing records.

Here I've done two things:

+ Add `on: :create` to the new validations where schools have some invalid records
+ Add `unless: :rejected` to items with a unique condition where new signups may overlap with rejected schools.

I've documented the errors in this sheet[1]. Some of the optional invalid codes could be fixed manually by nulling them if they aren't required, but since that can't be done for the required codes, I've handled them all the same way.

https://docs.google.com/spreadsheets/d/1ZwkCrRkVeUcgUaDuDxSZljlhntmK1Az8J5--Y0bSBrI/edit?gid=0#gid=0
@cla-bot cla-bot Bot added the cla-signed label Jun 12, 2026
@zetter-rpf zetter-rpf marked this pull request as ready for review June 12, 2026 11:21
Copilot AI review requested due to automatic review settings June 12, 2026 11:21
@github-actions

Copy link
Copy Markdown

Test coverage

91.57% line coverage reported by SimpleCov.
Run: https://github.com/RaspberryPiFoundation/editor-api/actions/runs/27412521161

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adjusts School model validations to avoid invalidating existing schools records already present in the database, while updating model specs to reflect the intended “validate-on-create” behavior and rejected-record uniqueness rules.

Changes:

  • Scope several validations to on: :create to prevent updates failing for legacy invalid data.
  • Adjust uniqueness behavior around rejected schools (and add a spec for creator_id reuse).
  • Update validation specs to explicitly assert behavior for new records.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 4 comments.

File Description
app/models/school.rb Changes validation contexts (on: :create) and adds unless: :rejected? to avoid conflicts with rejected schools.
spec/models/school_spec.rb Updates/clarifies validation examples and adds coverage for creator_id reuse when the original school is rejected.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread app/models/school.rb
Comment thread app/models/school.rb
Comment thread app/models/school.rb
Comment thread app/models/school.rb
@zetter-rpf zetter-rpf merged commit 50b653a into main Jun 12, 2026
6 checks passed
@zetter-rpf zetter-rpf deleted the fix-invalid-schools branch June 12, 2026 12:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants